/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cf.dao.impl;

import java.util.List;

import com.cf.modelo.TbCategoria;
import com.cf.modelo.TbSubcategoria;
import com.cf.modelo.TbTarea;
import com.cf.util.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Soltecn2
 */

@Service
@Transactional
public class CategoriaDao {



    public static List<TbCategoria> listCategoria() {
     Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        
        return session.createQuery("from TbCategoria").list();

    }
    public static List<TbSubcategoria> listSubCategoria(TbCategoria cat){
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        
        String sqlquery = "from TbSubcategoria where tbCategoria.codigo = :cat";
            return session.createQuery(sqlquery).setString("cat", ""+cat.getCodigo()).list();
    }
    
    public static List<TbTarea> listTareas(TbSubcategoria scat){
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        
        String sqlquery = "from TbTarea where tbSubcategoria.codigo = :scat";
            return session.createQuery(sqlquery).setString("scat", ""+scat.getCodigo()).list();
    }
}
